package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {
	//查找未关联的
	public List<Customer> findByFixedAreaIdIsNull();
	//查找已经关联的
	public List<Customer> findByFixedAreaId(String fixedAreaId);
	//修改未关联的为关联
	@Query("update Customer set fixedAreaId = ? where id = ?")
	@Modifying
	public void updateToAssociation(String fixedAreaId , Integer id);
	
	//解除关联
	@Query("update Customer set fixedAreaId = null where fixedAreaId = ?")
	@Modifying
	public void clearAssociation(String fixedAreaId);
	
	
	public Customer findByTelephone(String telephone);
	
	@Query("update Customer set type = 1 where telephone = ?")
	@Modifying
	public void updateType(String telephone);
	
	
	public Customer findByTelephoneAndPassword(String telephone, String password);
	
	
	@Query("select fixedAreaId from Customer where address = ?")
	public String findFixedAreaByAddress(String address);
}
